import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/viewmodel/patrol/offline_patrol_list_view_model.dart';
import 'package:ls_work/viewmodel/patrol/offline_patrol_point_list_view_model.dart';

import '../../res/colors.dart';

class OfflinePatrolPointListWidget extends BaseStatefulMvvmWidget {
  final dynamic taskId;

  OfflinePatrolPointListWidget({required this.taskId});

  @override
  State<StatefulWidget> createState() => _OfflinePatrolPointListState();
}

class _OfflinePatrolPointListState extends BaseMvvmListState<
    OfflinePatrolPointListViewModel, OfflinePatrolPointListWidget> {
  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return loadingContentWidget;
  }

  @override
  Widget createItemWidget(int index) {
    var checked = true;
    var item = viewModel.listItems[index];
    return Stack(
      alignment: Alignment.topCenter,
      children: [
        Positioned(
          child: Text(
            item.executeDate??"",
            textAlign: TextAlign.end,
            style: TextStyle(height: 1.2, fontSize: 15,),
          ),
          left: 0,
          width: 160,
        ),
        Column(
          children: [
            Container(
              width: 1,
              color: Colours.app_main,
            ),
            ((item.status==1||!item.executeDate.isNullOrEmpty())?Icon(Icons.check,size: 15,color: Colours.app_main,):Container()).addToContainer(
                width: 20,
                height: 20,
                alignment: Alignment.center,
                decoration: BoxDecoration(
                    shape: BoxShape.circle,
                    border: Border.all(width: 2, color: Colours.app_main))),
            index==viewModel.listItems.length-1?Container():Container(
              width: 1,
              color: Colours.app_main,
              height: 50,
            ),
          ],
        ).addToContainer(margin: EdgeInsets.symmetric(horizontal: 20)),
        Positioned(
          right: 0,
          width: 160,
          child: Text(
            item.pointName??"",
            style: TextStyle(height: 1.2, fontSize: 15),
          ),
        )
      ],
    );
  }

  @override
  OfflinePatrolPointListViewModel createViewModel() {
    return OfflinePatrolPointListViewModel(context,taskId: widget.taskId);
  }
}
